package com.vancouver.knows.business.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.pangu.bean.IInfo;

import java.util.List;

/**
 * Created by Chris Li on 2016-07-12.
 */
public class UserPostInfo implements IInfo {

    public static final String DRAFT_STATUS = "draft";
    public static final String PUBLISH_STATUS = "publish";
    public static final String EXPIRED_STATUS = "expired";

    @JSONField(name = "post_id")
    private String id;
    @JSONField(name = "comment_count")
    private int commentCount;
    @JSONField(name = "follow_count")
    private String followCount;
    @JSONField(name = "view_count")
    private String viewCount;
    @JSONField(name = "post_content_summary")
    private String postContentSummary;
    @JSONField(name = "post_date_gmt")
    private String pdg;
    @JSONField(name = "post_author_avatar")
    private String authorAvatar;
    @JSONField(name = "post_author")
    private String postAuthor;
    @JSONField(name = "post_author_id")
    private String authorId;
    @JSONField(name = "userpost_attachment_image_array")
    private List<String> postImages;
    @JSONField(name = "category")
    private List<CategoryInfo> categories;
    @JSONField(name = "sub_category")
    private List<CategoryInfo> subcategories;
    @JSONField(name = "user_followed")
    private String userFollowed;
    @JSONField(name = "post_date")
    private String date;
    @JSONField(name = "post_status")
    private String status;
    @JSONField(name = "post_modified_gmt")
    private String pmg;
    @JSONField(name = "post_modified")
    private String dateModified;

    // flags used to prevent multiple increments/decrements
    private boolean hasBeenIncremented = false;
    private boolean hasBeenDecremented = false;

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public int getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }

    public String getFollowCount() {
        if (followCount == null) {
            return String.valueOf(0);
        }

        return followCount;
    }

    public void setFollowCount(String followCount) {
        this.followCount = followCount;
    }

    public String getPostContentSummary() {
        return postContentSummary;
    }

    public void setPostContentSummary(String postContentSummary) {
        this.postContentSummary = postContentSummary;
    }

    public String getPdg() {
        return pdg;
    }

    public void setPdg(String pdg) {
        this.pdg = pdg;
    }

    public String getAuthorAvatar() {
        return authorAvatar;
    }

    public void setAuthorAvatar(String authorAvatar) {
        this.authorAvatar = authorAvatar;
    }

    public List<String> getPostImages() {
        return postImages;
    }

    public void setPostImages(List<String> postImages) {
        this.postImages = postImages;
    }

    public List<CategoryInfo> getCategories() {
        return categories;
    }

    public void setCategories(List<CategoryInfo> categories) {
        this.categories = categories;
    }

    public List<CategoryInfo> getSubcategories() {
        return subcategories;
    }

    public void setSubcategories(List<CategoryInfo> subcategories) {
        this.subcategories = subcategories;
    }

    public String getPostAuthor() {
        return postAuthor;
    }

    public void setPostAuthor(String postAuthor) {
        this.postAuthor = postAuthor;
    }

    public String getUserFollowed() {
        return userFollowed;
    }

    public void setUserFollowed(String userFollowed) {
        this.userFollowed = userFollowed;
    }

    public String getViewCount() {
        return viewCount;
    }

    public void setViewCount(String viewCount) {
        this.viewCount = viewCount;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getAuthorId() {
        return authorId;
    }

    public void setAuthorId(String authorId) {
        this.authorId = authorId;
    }

    public void incrementFollowCount() {
        int followCountValue = 0;
        if (followCount != null) {
            followCountValue = Integer.valueOf(followCount);
        }

        if (hasBeenIncremented) {
            return;
        }

        followCount = String.valueOf(followCountValue + 1);
        hasBeenIncremented = true;
        hasBeenDecremented = false;
    }

    public void decrementFollowCount() {
        int followCountValue = 0;
        if (followCount != null) {
            followCountValue = Integer.valueOf(followCount);
        }

        if (hasBeenDecremented) {
            return;
        }

        if (followCountValue - 1 <= 0) {
            followCount = String.valueOf(0);
        } else {
            followCount = String.valueOf(followCountValue - 1);
        }

        hasBeenDecremented = true;
        hasBeenIncremented = false;
    }

    public String getPmg() {
        return pmg;
    }

    public void setPmg(String pmg) {
        this.pmg = pmg;
    }

    public String getDateModified() {
        return dateModified;
    }

    public void setDateModified(String dateModified) {
        this.dateModified = dateModified;
    }
}
